Productive R Workflow Module 3
1 Lesson 1
1.1 Clean tables
Author discusses two preferred methods for incorporating tables in Quarto documents. Different approaches are discussed in this link.
1.2 Interactive tables with DT
Here is one of my go-to techniques when showcasing Quarto 😍.
With just two extra lines of code, you can unveil an interactive table that allows:
sorting
filtering
searching
pagination
It offers readers the convenience of accessing the data directly within your report. The magic of this functionality rests in the DT library. DT stands for DataTables: the JavaScript library supports it.
1.3 Static tables with kable() from the package knitr
Code
| species | average_bill_length |
|---|---|
| Adelie | 38.79139 |
| Chinstrap | 48.83382 |
| Gentoo | 47.50488 |
2 Lesson 2
Interactive tables
An interactive chart allows the user to perform actions: zooming, hovering a marker to get a tooltip, choosing a variable to display and more.
R offers a set of packages called the html widgets.
They allow to build interactive charts directly from R. 🔥
This course is not about data visualization and I already curated the best packages for interactive dataviz in the R graph gallery.
2.1 Plotly and ggplotly()
Code
ggplotly provides information for each point displayed in the graph. On the following chart you can zoom, hover, pan, export to png and more!
I find plotly so convenient: it’s an instant win without the need to learn anything new!
However, it’s not always the ideal choice. For instance Leaflet is better suited for mapping, and Dygraph excels in handling time series data. I’ve detailed these alternatives in the R Graph Gallery if you’re interested!
Also, remember that not all graphs require interactivity. For example, a basic bar chart remains just as effective in its static form, containing all the necessary information.
3 Lesson 3
Report header
In Quarto, you have the flexibility to include extensive information in the document header.
While the official documentation offers a comprehensive list of options, it’s important to strike a balance to prevent overwhelming readers.
Here’s an example of a Quarto header that effectively incorporates these elements in the YAML section of the Quarto document :
title: "Exploring the Simpson's Paradox..."
subtitle: "And simultaneously demonstrating ..."
description: "This document is..."
author:
name: "Yan Holtz"
affiliation: "Independant 😀"
email: yan.holtz.data@gmail.com
keywords: "Quarto, Paradox, Data Analysis"
date: today
3.0.1 Header appearance
With our informative header in place, let’s enhance its visual appeal.
One effective method is to utilize the title-block-banner option to introduce a background color, adding depth to the header. It subtly elevates its presence.
Quarto opens up endless possibilities for customization.
→ The Front Matter and Title blocks sections provide a comprehensive list of out-of-the-box options, covering licenses, copyrights, citations, multiple authors, metadata labels, and more.
→ Later in the course, we’ll explore CSS techniques to customize any element within the report.
→ For advanced users, template partials offer the ability to build the header structure from scratch, although this is a more advanced feature.
4 Lesson 4
Apply your style with CSS
his course teaches you how to transform your R code into a visually appealing report in HTML format.
Essentially, we’re creating a miniature website 🔥!
It is time to understand what HTML is, and explore how to personalize it using CSS, a stylesheet language.
Hello World!
I am a tiny website

When encountering a tag like h1, it recognizes it as a level 1 title and know how to format it accordingly. Same with the p tag that stands for paragraph, and all other tag types.
4.1 Style it with CSS
CSS is the language we use to style an HTML document.
Basically, we could create a file called style.css and add the following content in it:
h1 {
color: red;
}
Quarto, HTML and CSS
5 Lesson 5
Create your dataviz theme
Creating a custom theme for ggplot2
5.1 The theme() function
Code
library(tidyverse)
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
labs(title = "Customized Scatterplot", x = "Miles Per Gallon", y = "Weight") +
theme(
plot.title = element_text(color = "#69b3a2", size = 14, face = "bold"),
plot.margin = margin(3, 3, 3, 3, "cm")
)5.2 A set of predefined theme
Customizing a theme can feel overwhelming, with numerous options available to tweak and adjust.
However, a plethora of predefined themes exist, ready to be utilized in a matter of seconds!
Within the ggplot2 library alone, eight distinct themes are readily available, with theme_grey() serving as the default and theme_minimal emerging as a popular alternative
Furthermore, beyond ggplot2’s native themes, numerous external packages offer additional thematic options. Among them, one that I love is the theme_ipsum() theme from the hrbrthemes package:
Code
library(hrbrthemes)
library(tidyverse)
ggplot(mtcars, aes(x = mpg, y = wt)) +
geom_point() +
labs(title = "Customized Scatterplot", x = "Miles Per Gallon", y = "Weight") +
theme_ipsum() +
theme(
plot.title = element_text(color = "#69b3a2", size = 14, face = "bold"),
)5.3 Make your own theme
To elevate your visualizations to the next level of refinement, creating your own theme based on one of the predefined themes is the optimal strategy.
For example, let’s build a theme called yan_holtz_theme which builds upon the ipsum theme:
Code
yan_holtz_theme <- function() {
theme_ipsum() +
theme(
plot.title = element_text(color = "#69b3a2", size = 18, face = "bold"),
axis.text.x = element_text(size = 7),
axis.text.y = element_text(size = 7)
)
}This theme changes the title color and makes it pretty big. It also decreases the size of the axis text elements.
Now, let’s apply the theme to a graph:
Code
mtcars |>
ggplot(aes(x = mpg, y = wt)) +
geom_point() +
labs(title = "Customized Scatterplot",
x = "Miles Per Gallon", y = "Weight") +
yan_holtz_theme()This is convenient! I can now use the yan_holtz_theme() on any chart to have an uniformity without repeating myself too much.
You can also set the theme at the beginning of your Quarto doc and stop worrying about style for the whole study.
theme_set(yan_holtz_theme())
6 Lesson 6
More Quarto tips
The level of customization possible in a Quarto document is practically limitless. 🙃
In the previous lesson, I endeavored to distill the most essential concepts for you. However, enumerating all the possibilities would likely result in a rather tedious course.
Instead, armed with a solid Quarto foundation, I recommend perusing the compilation of Quarto tips and tricks I maintain.
I’m confident you’ll discover several valuable insights that you’ll be eager to incorporate into your next report!